#{extends 'main.html'/}
<script type="text/javascript">
   //user,dept初始值,放在最外面，让所有方法都能读取
    var groupicon = "/public/ligerUI/skins/icons/communication.gif";
    //var tag=${tag};
$(function () {
	var pvData = eval($("#pvDate").val());
	var consProjectData = eval($("#consProjectDate").val());
 
   /* 
    var queryform = $("#queryform");
    queryform.ligerForm({
        inputWidth: 180, labelWidth: 70, space: 10,
        fields: [
        { display: "月份查询", name: "searchDate", newline: false, type: "date",height:30,
        	group: "工程形象建设信息查询", groupicon: groupicon}, 
        ]
    });
    
    $("#queryButton").ligerButton(
        {
            click: function (){
                $(queryform).submit();
            },
            width: 50, text: '历史查询'
        }
    )
    $("#currentSearch").ligerButton(
        {
            click: function (){
            	var searchDate = new Date().format("yyyy-MM-dd");
            	$.getJSON("/pvReport/search",{searchDate:searchDate},function(data){
            		grid.loadData(data);
            	});
            },
            width: 50, text: '当前月查询'
        }
    )
    

    $(queryform).bind("submit",function(){
    	var searchDate =$("#searchDate").val();
    	var action = $(queryform).attr("action");
    	$.getJSON(action,{searchDate:searchDate},function(data){
    		grid.loadData(data);
    	});
    	return false;
    }) 
    */
    	
    var detailWin = null, curentData = null, currentIsAddNew;
	var mainform = $("#mainform");
    
    $(f_initGrid);
    
    function f_initGrid()
    { 
        grid = manager = $("#maingrid").ligerGrid({
            columns: [
                { display: 'id', name: "id", width: 50,  hide: true},
                { display: 'pvId', name: "pvId", width: 50,  hide: true},
                { display: 'consProjectId', name: "consProjectId", width: 50,  hide: true},
                { display: '描述', name: 'pvDescribe', width: 100, type: 'string', align:'left'},
                { display: '本月完成', name: 'quanlity',width: 100, type: 'string', align:'left'},
                { display: '累计完成', name: 'accumulateComp',width: 100, type: 'string', align:'left'},
                { display: '单位', name: 'pvUnitQuantity',width: 100, type: 'string', align:'left'},
                { display: '所属基建工程', name: 'consProjectName',width:140, type: 'string', align:'left'},
                { display: '所属月份', name: 'consProjectDate',width: 80, type: 'string', align:'left'},
                { display: '录入人', name: 'recordUserName',width: 100, type: 'date', align:'left'},
                { display: '修改人', name: 'modifyUserName',width: 100, type: 'date', align:'left'},
                { display: '备注', name: 'remark',width: 200, type: 'text', align:'left'}
            ],
            isScroll: true,
            frozen:false,
            width: '100%',
            frozen:true,
            url: "/pvReport/json",
			method: "GET",                
            title:"工程形象建设统计表",
            pageSize: 30,
            height:425,
			rownumbers:false,
            toolbar: { items: [
               { text: '添加', click: addRow, icon: 'add' },
               { line: true },
               { text: '修改', click: modifyRow, icon: 'modify' },
               { line: true },
               { text: '删除', click: deleteRow, icon: 'delete' }
           ] }
        });
             
    }
    
    function addRow(){
    	showDetail({}, false);
    }
    function modifyRow(){
    	 var selected = grid.getSelected();
         if (!selected) { LG.tip('请选择行!'); return }    
         showDetail({            
             id: selected.id,
             pvId:selected.pvId,
             consProjectId:selected.consProjectId,
             quanlity: selected.quanlity,
             accumulateComp:selected.accumulateComp,
             belongDate: selected.belongDate,
             remark: selected.remark,
         }, false);
    }
    function deleteRow(){
    	f_delete({
    		selected:grid.getSelected(),
    		grid:grid,
    		url:"/pvReport/delete?id="
    	});
    }
    function showDetail(data, isAddNew)
    {
      currentData = data;
      currentIsAddNew = isAddNew;
      if (detailWin)
      {
          detailWin.show(); 
      }
      else
      {
          //创建表单结构
          
          mainform.ligerForm({
          inputWidth: 280,
          fields: [
     			{ name: "pvReport.id", type: "hidden" },
     			{ display: "描述", name: "typeHide", comboboxName: "typeCombox", newline: true, 
       				labelWidth: 100, width: 220, space: 30, type: "select",
       				options: {data: pvData, valueField: 'pvId',valueFieldID: 'pvReport.projectVisuzlize.id'},
       				validate: { required: true} 
     			},
     			{ display: "本月完成", name: "pvReport.quanlity", newline: true, 
     				labelWidth: 100, width: 220, space: 30, type: "number", 
     				validate: { required: true,max:999999999,min:1} },
     			{ display: "累计完成", name: "pvReport.accumulateComp", newline: true, 
         				labelWidth: 100, width: 220, space: 30, type: "number", 
         				validate: { required: true,max:999999999,min:1} },
         		{ display: "所属基建工程", name: "typeHide", comboboxName: "conProjectCombox", newline: true, 
               			  labelWidth: 100, width: 220, space: 30, type: "select",
               			  options: {data: consProjectData, valueField: 'consProjectId', valueFieldID: 'pvReport.consProject.id'} },
         		{ display: '备注', name: 'pvReport.remark',labelWidth: 100, width: 220,space: 30, type: 'area', align:'left',
         			validate: { required: false,maxlength:100} 
         		}
                                                 
          ],         			
              toJSON: JSON2.stringify
          });            

          detailWin = $.ligerDialog.open({
              target: $("#detail"),
              width: 450, height: 240, top:80,
              buttons: [
              { text: '确定', onclick: function () { $("#mainform").submit(); } },
              { text: '取消', onclick: function () { detailWin.hide(); } }
              ]
          });
      }
      
      if (currentData)
      {    	  
          $("[name$=id]").val(currentData.id)
          $("#typeCombox").ligerGetComboBoxManager().setValue(currentData.pvId);
          $("#conProjectCombox").ligerGetComboBoxManager().setValue(currentData.consProjectId);
          $("[name$=quanlity]").val(currentData.quanlity);
          $("[name$=accumulateComp]").val(currentData.accumulateComp);
          $("[name$='consProject.id']").val(currentData.belongDate);
          $("[name$=remark]").val(currentData.remark);              
      }
      
      formSumit({
  		  formId : "mainform",
  		  url :'/pvReport/add',
  		  grid:grid,
  		  dialog :detailWin,
  		  sumitSuccess :null,
  		  beforeSubmit : null
  	  });
    }
})
</script>
<input id="pvDate" value="${pVisualizes}" type="hidden"/>
<input id="consProjectDate" value="${consProjects}" type="hidden"/>
<div id="query" style="height: 50px;">
    <form id = "queryform" method="post" action="/pvReport/search"></form>
    <div id="queryButton" style="display: inline;"></div>
    <div id="currentSearch" style="display: inline;"></div>
</div>
<div class="l-clear"></div>
<div id="maingrid" style="margin-top: 1px"></div>
<br />
<div style="display: none;"></div>
<div id="detail" style="display: none;">
	<form id="mainform" method="post" action=""></form>
</div>


